#include<iostream>

using namespace std;

void skip_to_int()
{
  if(cin.fail())
    {
      cin.clear();
      for(char ch;cin>>ch;)
	{
	  if(isdigit(ch)||ch=='-')
	    {
	      cin.unget();
	      return;
	    }
	}
    }
  cerr<<"no input!"<<endl;
}

int get_int()
{
  int n=0;
  while(true)
    {
      if(cin>>n) return n;
      cout<<"Sorry,that was not a number.Please try again."<<endl;
      skip_to_int();
    }
}

int get_int(int low,int high)  //require the input integer has a upper and lower bound
{
  cout<<"Please enter an integer in the range"<<endl;

  while(true)
    {
      int n=get_int();
      if(n>=low&&n<=high)
	return n;
      cout<<"Sorry,"<<n<<" is not in the range ["<<low<<','<<high<<"].Please try again"<<endl;
    }
}

int main(int argc,char *argv[])
{
  int n=get_int(1,10);
  cout<<n<<endl;
  return 0;
}
